package cn.webrx;

import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class Set1 {
    public static void main(String[] args) {
        //Set 就Collection 接口子接口  存储唯一对象
        Set<String> set = new HashSet<>();
        String a = new String("ok");
        String b = new String("ok");
        //Set 集合添加数据
        set.add(b);
        set.add(a);

        set.addAll(List.of("java", "java", "javascript"));
        System.out.println(set.size());

        //清空删除元素
        //set.clear();
        //set.remove("java");


        System.out.println(set);
        for(String t : set){
            System.out.println(t);
            System.out.println(t == a);
            System.out.println(t == b);
            System.out.println("--------------------");
        }

        System.out.println(set.contains("ok"));

        //迭代器工具类，快速遍历
        Iterator<String> it = set.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        set.forEach(System.out::println);

    }
}
